<template>
	<!-- 员工详情 -->
  <div class="stu">
	 <el-dialog v-loading="loading"  :title="num==1?'编辑贫困户信息':'新增贫困户信息'" :visible.sync="dialogVisible" width="35%" :before-close="handleClose"  :close-on-click-modal='false'>
	   <!-- <p class="pbox" style="text-align: center;width:100%;font-size:30px;height:40px;">员工信息详情</p> -->

	    <div style="width:100%;padding-bottom:20px;">
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>选择地区</p>
					<el-select :disabled='num==1' style='width:37%;' @change='activess.group_name="";' v-model="activess.village_name" clearable filterable placeholder="选择行政村">
					  <el-option v-for='i in $store.state.cunid' :label="i.label" :value="i.label"></el-option>
					</el-select>
					<el-select :disabled='num==1' style='width:37%;' v-model="activess.group_name" clearable filterable placeholder="选择村组">
					  <el-option v-for='i in activeput(gitcode(activess.village_name,$store.state.cunid),$store.state.cunzuid)' :label="i.label" :value="i.label"></el-option>
					</el-select>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>户编号</p>
					<el-input style='width:75%;' :disabled='num==1' placeholder="请输入" v-model="activess.h_number" clearable></el-input>
			</div>
			<!-- <div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>人员编号</p>
					<el-input style='width:75%;' :disabled='num==1?true:false' placeholder="请输入" v-model="activess.p_number" clearable></el-input>
			</div> -->
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>姓名</p>
					<el-input :disabled='num==1' style='width:75%;' placeholder="请输入" v-model="activess.pop_name" clearable></el-input>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>身份证号</p>
					<el-input style='width:75%;' :disabled='num==1?true:false' placeholder="请输入" v-model="activess.card" clearable></el-input>
			</div>
			<!-- <div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>家庭人数</p>
					<el-input style='width:75%;' placeholder="请输入" type='number' min='0' v-model="activess.unit_name" clearable></el-input>
			</div> -->
			<!-- <div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>与户主关系</p>
					<el-select style="width:75%;border:none;" class="pboxc1" v-model="activess.house_relation" clearable filterable placeholder="请选择">
					   <el-option :label="'户主'" :value="'户主'"></el-option>
					   <el-option :label="'配偶'" :value="'配偶'"></el-option>
					   <el-option :label="'之子'" :value="'之子'"></el-option>
					   <el-option :label="'之孙'" :value="'之孙'"></el-option>
					</el-select>
			</div> -->
			<!-- <div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>民族</p>
					<el-select style="width:75%;border:none;" class="pboxc1" v-model="activess.nation_id" clearable filterable placeholder="请选择">
					  <el-option v-for='item in $store.state.mingzu_box' :key='item.value' :label="item.label" :value="item.value"></el-option>
					</el-select>
			</div> -->
			<!-- <div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>文化程度</p>
					<el-select style="width:75%;border:none;" class="pboxc1" v-model="activess.edu_id" clearable filterable placeholder="请选择">
					  <el-option v-for='item in $store.state.xueli' :key='item.value' :label="item.label" :value="item.value"></el-option>
					</el-select>
			</div> -->
			<!-- <div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>健康状况</p>
					<el-select style="width:75%;border:none;" class="pboxc1" v-model="activess.health_id" clearable filterable placeholder="请选择">
					  <el-option v-for='item in $store.state.HEALTH_S_T' :key='item.value' :label="item.label" :value="item.value"></el-option>
					</el-select>
			</div> -->
			<!-- <div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>劳动技能</p>
					<el-select style="width:75%;border:none;" class="pboxc1" v-model="activess.pover_id" clearable filterable placeholder="请选择">
					  <el-option v-for='item in $store.state.LABOR_S_T' :key='item.value' :label="item.label" :value="item.value"></el-option>
					</el-select>
			</div> -->
			<!-- <div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>务工时间</p>
					<el-input style='width:75%;' placeholder="请输入" type='number' min='0' v-model="activess.year" clearable>
						 <template slot="append">（月）</template>
					</el-input>
			</div> -->
			<!-- <div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>参加大病医疗</p>
					<el-select style="width:75%;border:none;" class="pboxc1" v-model="activess.is_treatment" clearable filterable placeholder="请选择">
					   <el-option :label="'是'" :value="'1'"></el-option>
					   <el-option :label="'否'" :value="'0'"></el-option>
					</el-select>
			</div> -->
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>贫困户类型</p>
					<el-select style="width:75%;border:none;" class="pboxc1" v-model="activess.pover_p_id" clearable filterable placeholder="请选择">
					  <el-option v-for='item in $store.state.POVER_S_T' :key='item.value' :label="item.label" :value="item.value"></el-option>
					</el-select>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>脱贫属性</p>
					<el-select style="width:75%;border:none;" class="pboxc1" v-model="activess.pover_text" clearable filterable placeholder="请选择">
					  <el-option :label="'已脱贫'" :value="'已脱贫'"></el-option>
					  <el-option :label="'未脱贫'" :value="'未脱贫'"></el-option>
					</el-select>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>脱贫政策</p>
					<el-select style="width:75%;border:none;"  class="pboxc1" v-model="activess.poor_rid_id" clearable filterable placeholder="请选择">
					  <el-option v-for='item in $store.state.tpzc_id' :key='item.id' :label="item.title" :value="item.id"></el-option>
					</el-select>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>致贫原因</p>
					<el-input style='width:75%;' placeholder="请输入" v-model="activess.major_pover" clearable></el-input>
			</div>
			
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>识别时间</p>
					 <el-date-picker v-model="activess.poor_time" style='width:75%;'
					      type="datetime"
						  value-format='yyyy-MM-dd HH:mm:ss'
					      placeholder="选择日期时间">
					    </el-date-picker>
			</div>
			
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>脱贫时间</p>
					 <el-date-picker v-model="activess.t_poor_time" style='width:75%;'
					       type="date"
						   value-format='yyyy-MM-dd'
					       placeholder="选择日期">
					     </el-date-picker>
			</div>
			
		</div>	
		<div style="width:100%;height:40px;margin-top:20px;">
	      <div style="width:170px;margin: 0 auto;">
	        <el-button type="danger" @click="handleClose">取 消</el-button>
	        <el-button type="primary" style='float:right;' @click="git_acts">确 定</el-button>
	      </div>
		</div>
	 </el-dialog>
	
  </div>
</template>

<script>
import $ from 'jquery'
export default {
  name: 'stu',
  components: {},//声明子组件
  computed:{
	  docsa(){
	  		return function(i){
	  			for(let j=0;j<this.$store.state.suju_box.length;j++){
	  				if(this.$store.state.suju_box[j].value==i){
	  					return this.$store.state.suju_box[j].label;
	  				}
	  			}
	  		}  
	  },
	  activeput(){//联动判断，code 为上一级的code  act为当前未赛选的数据字典
	  	return function(code,act){
	  		let a = [];
	  		for(let i=0;i<act.length;i++){
	  			if(act[i].own_code==code){
	  				a.push(act[i]);
	  			}
	  		}
	  		return a;
	  	}
	  },
	  gitcode(){//通过id获取code
	  	return function(id,act){
	  		for(let i=0;i<act.length;i++){
	  			if(id==act[i].label){
	  				return act[i].code;
	  			    break
	  			}
	  		}
	  	}
	  },
  },
  data(){
	  return {
		loading:false,
		btn_shou:false,
		dialogVisible: false,
		activess:{
			      county_name:'',//县名
				  town_name:'',//乡镇名
				  village_name:'',//村名
				  group_name:'',//组名
				  h_number:'',//户编号
				  p_number:'',//人编号
				  card:'',//身份证号码
				  pop_name:'',//姓名
				  house_relation:'',//关系
				  edu_id:'',//教育程度ID
				  health_id:'',//健康ID
				  pover_id:'',//劳动技能ID(一般劳动力，丧失劳动力，技能劳动力，无劳动力)
				  t_poor_time:'',//脱贫时间
				  poor_time:'',//识别时间(正式申请成为贫困户时间)
				  poor_rid_id:'',//脱贫政策ID
				  nation_id:'',//民族id
				  year:'',//务工时间(多少个月)
				  is_treatment:'',//是否参加大病医疗(1是 0否)
				  pover_text:'',//脱贫属性文案(已脱贫（享受政策）)
				  pover_p_id:'',//贫困户类型ID
				  major_pover:'',//主要致贫原因
				  poor_house_id:'',//贫困户ID（主键）
				  id:'',//贫困人口ID（主键）
				  
				  
		},
		
		renbox:[],
		num:0,
	  }
  },
  methods:{
	  
	  git_act(i,num){//获取数据的同打开狂口
	      if(num==1){
			  this.activess = i;
			  console.log(this.activess);
			  // this.activess.p_number = this.activess.poor_pop[0].p_number;
			  // this.activess.pop_name = this.activess.poor_pop[0].pop_name;
			  // this.activess.card = this.activess.poor_pop[0].card;
			  // this.activess.house_relation = this.activess.poor_pop[0].house_relation;
			  // this.activess.nation_id = this.activess.poor_pop[0].nation_id;
			  // this.activess.edu_id = this.activess.poor_pop[0].edu_id;
			  // this.activess.health_id = this.activess.poor_pop[0].health_id;
			  // this.activess.pover_id = this.activess.poor_pop[0].pover_id;
			  // this.activess.year = this.activess.poor_pop[0].year;
			  // this.activess.is_treatment =  this.activess.is_treatment+'';
			  this.activess.poor_rid_id = Number(this.activess.poor_rid_id);
		  }
		  this.num = num;
	      // console.log(this.activess,num);
	      this.dialogVisible=true;
	  },
	  git_acts(){//提交数据
	        console.log(this.activess)
	        // if(this.isNull(this.activess.village_name)){this.$message.error('请选择 行政村');return false}
	        // if(this.isNull(this.activess.group_name)){this.$message.error('请选择 村组');return false}
	  		if(this.isNull(this.activess.h_number)){this.$message.error('请输入 户编号');return false}
			// if(this.isNull(this.activess.p_number)){this.$message.error('请输入 人员编号');return false}
			if(this.isNull(this.activess.pop_name)){this.$message.error('请输入 姓名');return false}
			if(this.isNull(this.activess.card)){this.$message.error('请输入 身份证号');return false}
			if(this.iscard(this.activess.card)){this.$message.error('身份证号格式不正确');return false}
			// if(this.isNull(this.activess.house_relation)){this.$message.error('请选择 与户主关系');return false}
			// if(this.isNull(this.activess.nation_id)){this.$message.error('请选择 民族');return false}
			// if(this.isNull(this.activess.edu_id)){this.$message.error('请选择 文化程度');return false}
			// if(this.isNull(this.activess.health_id)){this.$message.error('请选择 健康状况');return false}
			// if(this.isNull(this.activess.pover_id)){this.$message.error('请选择 劳动技能');return false}
			// if(this.activess.year||this.activess.year==0){}else{this.$message.error('请输入 务工时间');return false}
			// if(this.activess.year<0){this.$message.error('务工时间不得小于0');return false}
			// if(this.isNull(this.activess.is_treatment)){this.$message.error('请选择 是否参加大病医疗');return false}
			if(this.isNull(this.activess.pover_p_id)){this.$message.error('请选择 贫困户类型');return false}
			if(this.isNull(this.activess.pover_text)){this.$message.error('请选择 脱贫属性');return false}
			
			if(this.isNull(this.activess.poor_rid_id)){this.$message.error('请选择 脱贫政策');return false}
			if(this.isNull(this.activess.major_pover)){this.$message.error('请输入 致贫原因');return false}
			if(this.isNull(this.activess.poor_time)){this.$message.error('请选择 识别时间');return false}
			if(this.isNull(this.activess.t_poor_time)){this.$message.error('请选择 脱贫时间');return false}
			// if(this.num==1){
			// 	this.activess.id = this.activess.poor_pop[0].id;
			// 	this.activess.poor_house_id = this.activess.poor_pop[0].poor_house_id;
			// }
			
			// this.activess.pover_text = this.id_title(this.$store.state.tpzc_id,this.activess.poor_rid_id);
			
	  		 let url = this.num==1?'/dj/user_pc/poor_house_modify':'/dj/user_pc/poor_insert';
	  		 $.ajax({url:url,type:'post',data:this.activess,dataType:'json',success:(res)=> {
	  		 	if(Object.prototype.toString.call(res) != '[object Object]'){res = JSON.parse(res)}
	  		 	 console.log(res,'提交');
	  		 	 if(res.code==200){
	  				this.$parent.git_act();
	  		 		this.$message({message: '操作成功',type: 'success'});
	  		 		this.dialogVisible=false;
	  				this.qin();
	  		 	  }else{
	  		 		 this.$message.error(res.msg);
	  		 	  }
	  		 	}
	  		 })
	  },
	  qin(){//清除
	  	this.activess={
			      county_name:'',//县名
				  town_name:'',//乡镇名
				  village_name:'',//村名
				  group_name:'',//组名
				  h_number:'',//户编号
				  p_number:'',//人编号
				  card:'',//身份证号码
				  pop_name:'',//姓名
				  house_relation:'',//关系
				  edu_id:'',//教育程度ID
				  health_id:'',//健康ID
				  pover_id:'',//劳动技能ID(一般劳动力，丧失劳动力，技能劳动力，无劳动力)
				  t_poor_time:'',//脱贫时间
				  poor_time:'',//识别时间(正式申请成为贫困户时间)
				  poor_rid_id:'',//脱贫政策ID
				  nation_id:'',//民族id
				  year:'',//务工时间(多少个月)
				  is_treatment:'',//是否参加大病医疗(1是 0否)
				  pover_text:'',//脱贫属性文案(已脱贫（享受政策）)
				  pover_p_id:'',//脱贫属性ID
				  major_pover:'',//主要致贫原因
				  poor_house_id:'',//贫困户ID（主键）
				  id:'',//贫困人口ID（主键）
		}
	  },
	  
	  handleClose(done){//监测用户点击x
	     this.$confirm('确定取消关闭吗？','提示',{confirmButtonText:'确定',cancelButtonText:'取消',type: 'warning'
	     }).then(() => {
	  	   this.dialogVisible = false;
	  	   this.qin();
		   this.$parent.git_act();
	  	}).catch(() => {});
	  },
	  
  },
  mounted(){
	  // this.git_ren()
  }
}
</script>
<style scoped="scoped">
	
	.pboxc1{
		float:left;
		width:70%;
		height:40px;
		border:1px solid rgba(242,242,242,1);
		font-size:14px;color:#666666;
		/* padding-left:18px; */
		text-align:left;
		/* overflow: hidden; */
		/* text-overflow:ellipsis; */
		/* white-space: nowrap; */
	}
	.tabbox{
		width:100%;
		height:40px;
		line-height: 30px;
		margin-top:23px;
	}
	.tabbox p{
		font-size:14px;
		color:#000000;
		width:19.5%;
		text-align:right;
		margin-right:28px;
		float:left;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
		font-family:Source Han Sans CN;
	}
	.pbox{
		width:10%;
		text-align:right;
		height:26px;
		margin-bottom:20px;
		font-size:18px;
		color:#000101;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
		font-family:Source Han Sans CN;
		font-weight:600;
	}
</style>
